//
//  ScoresScene.m
//  cocoaTest
//
//  Created by binbinming on 10-2-11.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "ScoresScene.h"


@implementation ScoresScene
- (id) init
{
	if( (self=[super init]) )
	{ 
		id layer = [ColorLayer layerWithColor: ccc4(0,0,20,255)];	//RGBA
		[self addChild: layer];
		[self addChild:[ScoresLayer node]];
	}
	
	return self;
}
@end

@implementation ScoresLayer

- (id) init
{
	if( (self=[super init]) )
	{ 
		ccGridSize gs = {0,100};
		layout = [Grid3D gridWithSize:gs];
		//Load scores list.
		NSString *name = @"Name";
		NSString *pos  = @"Hot";
		Label *n = [Label labelWithString:name fontName:@"Arial" fontSize:23];
		Label *p = [Label labelWithString:pos fontName:@"Arial" fontSize:23];
		[self addChild:n];
		[self addChild:p];
		n.position = CGPointMake(200,450);
		p.position = CGPointMake(90,450);
		
		NSBundle *bundle = [NSBundle mainBundle];
		NSString *scorePath = [bundle pathForResource:@"scores" ofType:@"plist"];
		scoreList = [NSMutableDictionary dictionaryWithContentsOfFile:scorePath]; // because of 无序.
		NSArray *keys = [scoreList allKeys];
		//NSArray *vs   = [scoreList allValues];
		int gap = 0;
		for( id key in keys )
		{
			//NSNumber *value = [scoreList valueForKey:key];
			NSString *value = [[NSNumber numberWithInt:(gap+1)] stringValue];
			Label *mc = [Label labelWithString:value fontName:@"Arial" fontSize:22];
			Label *recoder = [Label labelWithString:key fontName:@"Arial" fontSize:22];
			[self addChild:mc];
			[self addChild:recoder];
			recoder.position = CGPointMake(200,400-gap*40);
			mc.position = CGPointMake(90,400-gap*40);
			gap++;
		}
	}
	
	return self;	
}

@end

